<template>
    <div class="song-list">
        <!-- 歌单详情 -->
        <van-nav-bar title="歌单详情"
         left-text="返回" 
         left-arrow 
        @click-left="onClickLeft"
        />
        <!-- 歌单的顶部 -->
        <div class="header">
            <img :src="song.logo">
            <h3>{{ song.dissname }}</h3>
            <div class="nick">
                <img :src="song.headurl">
                <span>{{ song.nickname }}</span>
            </div>
            <span>播放量:{{ song.visitnum | numFilter(1) }}万</span>
       
        </div>
        <!-- 歌曲列表 -->
        <div class="list">
            <van-list
            v-model="loading"
            :finished="finished"
            finished-text="没有更多了"
            @load="onLoad"
            >
            <div v-for="(item,index) in list" :key="index">
                <h4>{{ item.songname }}</h4>
                <div class="singer">
                    <span v-for="(singerItem,index) in item.singer" :key="index">{{ singerItem.name }}
                    <span v-show="index != item.singer.length -1">/</span>
                    </span>
                    <span class="dian">·</span>
                    <span v-show="item.albumname!=null">{{ item.albumname }}</span>
                </div>
            </div>
        </van-list>
        </div>
    </div>
</template>

<script>
export default {
    data() {
        return {
            song:{
            logo:"", //歌单的logo
            dissname:"", //歌单的名称
            headurl:"", //歌单制作者的头像
            nickname:"", //歌单制作者的名称
            visitnum: 0 ,// 播放量
            },
            songlist: [],
            songnum: 0, //歌曲数量
            list:[],
            loading: false,
            finished: false
        }
    },
    created() {
        this.getListData();
    },
    methods: {
        getListData() {
            this.$request('get', '/songlist', {
                id: this.$route.params.id
            }).then((res) => {
                console.log(res);
                this.song.logo = res.data.logo,
                this.song.dissname = res.data.dissname,
                this.song.headurl = res.data.headurl,
                this.song.nickname = res.data.nickname,
                this.song.visitnum = res.data.visitnum,
                this.songlist = res.data.songlist,
                this.songnum = res.data.songnum
            })
        },
        onClickLeft(){
            this.$router.go(-1);
        },
        onLoad(){
            setTimeout(() => {
                this.list = this.list.concat(this.songlist.splice(0,10))
                this.loading = false;

                if(this.list.length >= this.songnum){
                    this.finished = true;
                }
            },1000)
        }
    }
}
</script>

<style scoped>
 .header>img{
    border-radius: 1rem;
    width: 50%;
 }
 .nick>img{
    height: 2rem;
    border-radius: 50%;
    margin-right: 0.5rem;
 }
.nick>span{
    height: 2rem;
    font-size: 0.8rem;
    line-height: 2rem;
}
.nick{
    overflow: hidden;
    display: flex;
    justify-content: center;
    margin-bottom: 1rem;
}

.list{
    margin: 0 1rem;
}
.list h4{
    text-align: left;
    font-size: 1rem;
}
.singer{
    text-align: left;
}
.singer span{
    font-size: 0.8rem;
    color: rgb(160,160,190);
}
.dian{
    color: red;
    font-weight: 900;
    padding: 0 0.5rem;
}
</style>